<template>
  <div class="tab-bar-items" @click="itemClick">
    <div v-if="!isActive"><slot name="bar-icon"></slot></div>
    <div v-else><slot name="bar-icon-active"></slot></div>
    <div :style="activeStyle"><slot name="bar-text"></slot></div>
  </div>
</template>

<script>
  export default {
    name: "TabBarItems",
    props: {
      link: {
        type: String
      },
      TabColor: {
        type: String,
        default: 'red'
      }
    },
    methods: {
      itemClick() {
        return this.$router.replace(this.link).catch(err => err)
      }
    },
    computed: {
      isActive() {
        return this.$route.path.indexOf(this.link) !== -1
      },
      activeStyle() {
        return this.isActive ? {color: this.TabColor} : {}
      }
    }
  }
</script>

<style scoped>
  .tab-bar-items {
    height: 49px;
    flex: 1;
    margin-top: 11px;
    text-align: center;
    font-size: 14px;
  }
  .tab-bar-items img {
    width: 25px;
    height: 25px;
    vertical-align: middle;
  }
</style>
